IMPORT LIBRARY

In [0]:
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
import plotly.io as pio
import math

LOAD FILE

In [0]:
url = 'https://raw.githubusercontent.com/ubaiyusuf/VI/master/dataset.csv'
data = pd.read_csv(url)
data.head(5)
Out[0]:
Unnamed: 0 id name host_id host_name neighbourhood_group neighbourhood latitude longitude room_type price minimum_nights number_of_reviews last_review reviews_per_month calculated_host_listings_count availability_365
0 0 2539 Clean & quiet apt home by the park 2787 John Brooklyn Kensington 40.64749 -73.97237 Private room 149 1 9 2018-10-19 0.21 6 365
1 1 2595 Skylit Midtown Castle 2845 Jennifer Manhattan Midtown 40.75362 -73.98377 Entire home/apt 225 1 45 2019-05-21 0.38 2 355
2 2 3647 THE VILLAGE OF HARLEM....NEW YORK ! 4632 Elisabeth Manhattan Harlem 40.80902 -73.94190 Private room 150 3 0 NaN NaN 1 365
3 3 3831 Cozy Entire Floor of Brownstone 4869 LisaRoxanne Brooklyn Clinton Hill 40.68514 -73.95976 Entire home/apt 89 1 270 2019-07-05 4.64 1 194
4 4 5022 Entire Apt: Spacious Studio/Loft by central park 7192 Laura Manhattan East Harlem 40.79851 -73.94399 Entire home/apt 80 10 9 2018-11-19 0.10 1 0

Visualisasi Jumlah Persewaan Tiap Daerah

In [0]:
#BARPLOT

y_pos = np.arange(data['neighbourhood_group'].nunique())

plt.bar(y_pos, pd.value_counts(data['neighbourhood_group']), align='center', alpha=0.8)
plt.xticks(y_pos, data.neighbourhood_group.unique())
plt.ylabel('Jumlah')
plt.title('Jumlah persewaan tiap daerah')

plt.show()

Visualisasi Persentsase Jumlah Jenis Persewaan

In [0]:
#PIE CHART
fig = go.Figure(data=[go.Pie(labels=data.room_type.unique(), values=pd.value_counts(data['room_type']), hole=.3)])
fig.show()

Visualisasi Perbandingan Rata-Rata Review Tiap Bulan Terhadap Harga

In [0]:
#SCATTER
plt.scatter(data['reviews_per_month'], data['price'], c='red', alpha=0.5)
plt.title('Perbandingan rata-rata review tiap bulan dan harga')
plt.xlabel('rata-rata review per bulan')
plt.ylabel('harga sewa')
plt.show()

Visualisasi Perbandingan Jumlah Hari Ketersediaan Kamar Terhadap Jumlah Review

In [0]:
#SCATTER PLOTLY
d = [dict(
  type = 'scatter',
  x = data['availability_365'].tolist(),
  y = data['number_of_reviews'].tolist(),
  mode = 'markers',
  transforms = [dict(
    type = 'groupby',
    groups = data['neighbourhood_group'],
    styles = [
        dict(target = 'Brooklyn', value = dict(marker = dict(color = 'red'))),
        dict(target = 'Manhattan', value = dict(marker = dict(color = 'yellow'))),
        dict(target = 'Queens', value = dict(marker = dict(color = 'green'))),
        dict(target = 'Staten Island', value = dict(marker = dict(color = 'blue'))),
        dict(target = 'Bronx', value = dict(marker = dict(color = 'purple')))
    ]
  )]
)]

fig_dict = dict(data=d)
pio.show(fig_dict, validate=False)

Visualisasi Lokasi Persewaan

In [0]:
#MAPBOX
fig = px.scatter_mapbox(data, lat="latitude", lon="longitude", hover_name="name", hover_data=["price", "number_of_reviews"],
                        color="room_type", color_continuous_scale='Magma', zoom=9, height=300)
fig.update_layout(mapbox_style="open-street-map")
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

Visualisasi Persebaran Jumlah Review per Bulan Terhadap Harga dan Jumlah Hosting

In [0]:
#BUBBLE CHART
fig = px.scatter(data, x="price", y="reviews_per_month",
	         size="calculated_host_listings_count", color="neighbourhood_group",
                 hover_name="name", log_x=True, size_max=60)
fig.show()
In [0]: